﻿using RN;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {            
            if (GlobalService.FileLoader == null)
            {
               Loader.FileURL = @"D:\Desarrollo de Software\Lab3\Lab3\Config\Users.txt";
               GlobalService.FileLoader = new Loader();
               GlobalService.FileLoader.LoadClients();
               GlobalService.ClientManager = new ClientManager(GlobalService.FileLoader);
            }
        }

    }
    protected void ToIndex(object sender, EventArgs e)
    {
        
        string username = Username.Value;
        string password = Password.Value;

        if (GlobalService.ClientManager.validateUser(username, password))
        {
            Session[Definitions.CURRENT_CLIENT] = new Client(username, password);
            Response.Redirect("Index.aspx?user="+username);            
        }
        else
        {
            Username.Value = "Logging Error";
        }
    }
}